package com.lcu.student.controller;

import com.lcu.Result.Result;
import com.lcu.student.entity.Student;
import com.lcu.student.service.StudentService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.mongodb.core.aggregation.ArrayOperators;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/students")
public class StudentController {

    @Autowired
    private StudentService service;

    /**
     * 待条件的分页查询
     * @param currentPage
     * @param pageSize
     * @param student
     * @return
     */
    @PostMapping("/selectByPage/{currentPage}/{pageSize}")
    public Result selectByPage(@PathVariable int currentPage, @PathVariable int pageSize, @RequestBody Student student){
        return service.selectByPage(currentPage,pageSize,student);
    }

    /**
     * 根据id删除数据
     * @param id
     * @return
     */
    @DeleteMapping("/deleteById/{id}/{studentNumber}")
    public Result deleteById(@PathVariable int id,@PathVariable String studentNumber){
        return service.deleteById(id,studentNumber);
    }

    /**
     * 批量删除
     * @param selectIds
     * @return
     */
    @DeleteMapping("/deleteByIds")
    public Result deleteByIds(@RequestBody List<Integer> selectIds){
        return service.deleteByIds(selectIds);
    }

    /**
     * 添加数据
     * @param student
     * @return
     */
    @PostMapping("/addStudent")
    public Result addStudent(@RequestBody Student student){
        return service.addStudent(student);
    }

    @PutMapping("/updateById")
    public Result updateById(@RequestBody Student student){
        return service.updateById(student);
    }
}
